package cn.vehicle.biz.eventListener;

import cn.vehicle.biz.cache.LastPlateDetectedResultCache;
import cn.vehicle.biz.event.PlateDetectResultEvent;
import cn.vehicle.domains.ctx.PlateDetectContext;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class PlateDetectedResultCacheListener implements ApplicationListener<PlateDetectResultEvent> {

    @Resource
    private LastPlateDetectedResultCache lastPlateDetectedResultCache;

    @Override
    public void onApplicationEvent(PlateDetectResultEvent event) {
        PlateDetectContext plateDetectContext = event.getPlateDetectContext();

        if (!plateDetectContext.getIsOpen()) {
            return;
        }

        lastPlateDetectedResultCache.put(plateDetectContext.getCameraEntity().getCameraIp(), plateDetectContext);
    }
}
